use bigdecimal::BigDecimal;
use chrono::{DateTime, Utc}; // 数据库时间类型
use serde::{Deserialize, Serialize};
use sqlx::FromRow;

// ****============================== User  =================================****
#[derive(sqlx::FromRow, Debug)]
pub struct UserName {
    pub username: String,
}

#[derive(Debug, FromRow, Serialize, Deserialize)]
pub struct UserInfoRes {
    pub id: u64,
    pub username: String,
    pub tel: String,
    pub remark: Option<String>,
    pub created_at: DateTime<Utc>,
    pub updated_at: DateTime<Utc>,
}

#[derive(Debug, FromRow, Serialize, Deserialize)]
pub struct UserLoginAdminRes {
    pub id: u64,
    pub username: String,
    pub tel: String,
    pub password: String,
}

#[derive(Debug, FromRow, Serialize, Deserialize)]
pub struct UserList {
    pub list: Vec<UserInfoRes>,
    pub total: i64,
}

// ****============================== Topic  =================================****

#[derive(Debug, FromRow, Serialize, Deserialize)]
pub struct TopicInfoRes {
    pub id: u64,
    pub r#type: i32,
    pub name: String,
    pub topic_text: String,
    pub message: String,
    pub remark: String,
    pub created_at: DateTime<Utc>,
    pub updated_at: DateTime<Utc>,
}

#[derive(Debug, Serialize)]
pub struct TopicList {
    pub list: Vec<TopicInfoRes>,
    pub total: i64,
}

// ****============================== Device  =================================****
#[derive(Debug, FromRow, Serialize, Deserialize)]
pub struct DeviceInfoRes {
    pub id: u64,
    pub name: String,
    pub model: String,
    pub device_type: i64,
    pub power_type: u32,
    pub power_value: Option<String>,
    pub price: BigDecimal,
    pub device_img: Option<String>,
    pub remark: Option<String>,
    pub created_at: DateTime<Utc>,
    pub updated_at: DateTime<Utc>,
}

#[derive(Debug, Serialize)]
pub struct DeviceList {
    pub list: Vec<DeviceInfoRes>,
    pub total: i64,
}

// === core_control ===
#[derive(Debug, FromRow, Serialize)]
pub struct ControlCoreInfo {
    pub id: u64,
    pub name: String,
    pub model: String,
    pub price: BigDecimal,
    pub core_img: String,
    pub power: String,
    pub remark: String,
    pub created_at: DateTime<Utc>,
    pub updated_at: DateTime<Utc>,
}

#[derive(Debug, Serialize)]
pub struct ControlCoreList {
    pub list: Vec<ControlCoreInfo>,
    pub total: i64,
}

// ****============================== Modules  =================================****
#[derive(Debug, FromRow, Serialize)]
pub struct ModulesInfoRes {
    pub id: u64,
    pub name: String,
    pub modules_img: Option<String>,
    pub remark: Option<String>,
    pub created_at: DateTime<Utc>,
    pub updated_at: DateTime<Utc>,
}

#[derive(Debug, Serialize)]
pub struct ModulesList {
    pub list: Vec<ModulesInfoRes>,
    pub total: i64,
}

#[derive(Debug, FromRow, Serialize)]
pub struct ModulesDetailAll {
    pub modules_detail: ModulesInfoRes,
    pub task_list: Vec<TaskInfoRes>,
}

// ****============================== Task  =================================****
#[derive(Debug, FromRow, Serialize)]
pub struct TaskInfoRes {
    pub id: u64,
    pub core: u64,
    pub device: u64,
    pub topic: u64,
    pub gpio: String,
    pub task_name: String,
    pub created_at: DateTime<Utc>,
    pub updated_at: DateTime<Utc>,
}
